package com.py.credit.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.py.credit.dao.DeclarationManagementDao;
import com.py.credit.entity.DeclarationManagement;
import com.py.credit.service.DeclarationManagementService;
import com.py.credit.utils.SQLBuilder;
import com.py.framework.core.common.Page;

@Service
public class DeclarationManagementServiceImpl implements DeclarationManagementService {
	@Autowired
	private DeclarationManagementDao declarationManagementDao;

	@Override
	public List<DeclarationManagement> selectForPage(String type, Page page, String id, String root_id) {
		return declarationManagementDao.selectForPage(type, page, id, root_id);

	}

	@Transactional
	@Override
	public void updateById(String type, String id, String root_id, String state) {
		declarationManagementDao.updateById(type, id, root_id, state);
	}

	@Transactional
	@Override
	public void delListById(List<String> list) {
		declarationManagementDao.delListById(list);

	}

	@Override
	public DeclarationManagement selectIsExist(String type, String root_id) {
		return declarationManagementDao.selectIsExist(root_id);
	}

	@Transactional
	@Override
	public void insert(String update_person, String root_id, String type) {
		declarationManagementDao.insert(update_person, root_id, type);

	}

	@Transactional
	@Override
	public void updateIdCountListById(String cube_id_list, String id, String finance_id_list) {
		String i = new String();
		if (cube_id_list.isEmpty()) {
			i = "0";
		} else {
			List<String> idList = new ArrayList<String>();
			idList = java.util.Arrays.asList(cube_id_list.split(","));
			i = String.valueOf(idList.size());
		}
		String j = new String();
		if (finance_id_list.isEmpty()) {
			j = "0";
		} else {
			List<String> idList = new ArrayList<String>();
			idList = java.util.Arrays.asList(finance_id_list.split(","));
			j = String.valueOf(idList.size());
		}
		declarationManagementDao.updateIdCountListById(cube_id_list,
				String.valueOf(Integer.valueOf(i) + Integer.valueOf(j)), id, finance_id_list);
	}

	@Override
	public List<DeclarationManagement> selectXypjTable(String collection_type) {
		return declarationManagementDao.selectXypjTable(collection_type);
	}

	@Override
	public List<DeclarationManagement> selectTable(List<String> list) {
		return declarationManagementDao.selectTable(list);
	}

	@Override
	public List<Map<String, Object>> selectTableListByConditionForPage(String root_id, List<String> columns,
			String[] additionalColumns, String condition, Page page) {
		List<Map<String, Object>> GetList = new ArrayList<Map<String, Object>>();
		List<String> conditions = SQLBuilder.createConditionSql(condition);
		GetList = declarationManagementDao.selectTableListByConditionForPage(root_id, columns, additionalColumns,
				conditions, page);
		return GetList;
	}

}
